#include "stdio.h"
#include "math.h"
typedef struct LNode{
    int data;
    struct LNode* next;
}LNode;


int main(){
    LNode *L=NULL;
    LNode *r=NULL;
    LNode *cur=NULL;
    LNode *pre=NULL;
    int n=0;
    scanf("%d",&n);
    //插入
    for(int i=0;i<n;i++){
        int data=0;
        scanf("%d",&data);
        LNode *s = (LNode*)malloc(sizeof (LNode));
        s->data=data;
        s->next=NULL;
        if(L==NULL){
            L=s;
            r=L;
        } else{
            r->next=s;
            r=r->next;
        }
    }
    //删除
    int del=0;
    scanf("%d",&del);
    cur=L->next;
    pre=L;
    LNode *p=NULL;
    while (cur){
        if(cur->data==del){
            p=cur;
            pre->next=cur->next;
            cur=pre->next;
            free(p);
            n--;
        } else{
            pre=cur;
            cur=cur->next;
        }
    }
    if(L->data==del){
        p=L;
        L=L->next;
        free(p);
    }
    cur=L;
    while (cur!=NULL){
        printf("%d ",cur->data);
        cur=cur->next;
    }
    //释放全部空间
    cur=L;
    while (cur){
        p=cur;
        cur=cur->next;
        free(p);
    }
    return 0;
};